﻿// Mixin class that incorporates a layout when creating a control
define([
'Xjs/core/Composite',
'Xjs/core/util'
],
function (Composite, util) {
    'use strict';

    var type = 'layoutHolder', // Use the type registration to avoid recreating the type
    LayoutHolder = Xjs.getType(type);

    if (LayoutHolder) { // It has been already loaded
        return LayoutHolder;
    }

    // Renders the html from a component
    LayoutHolder = util.define({

        type: type, // Set the type

        initialize: function(conf) {
            if (conf.layout) {
            }

            return null;
        },

        // Overwrite the add child to handle the layout
        addChild: function (c) {
            var addChildFcn = Composite.prototype.addChild;

            if (this.layout) {
                var cmp = this.layout.getContainer(c);
                addChildFcn.call(cmp, c);
            }
            else {
                addChildFcn.call(this, c);
            }
        }
    });

    Xjs.registerType(LayoutHolder);

    return LayoutHolder;
});
